<?php
require 'auth.php';
require '../config/config.php';

if(!isset($_GET['id'])){
	header("Location: ../news.php");
	exit();
}
mydb_connect();

$qry = $conn->prepare("SELECT * FROM `news` WHERE id = :id");
$qry->execute(array('id' => $_GET['id']));
if(!$qry) echo die($qry->errorInfo());

$row = $qry->fetch();
if(file_exists("../images/" . $row['img_name'])){
$unlink = unlink("../images/" . $row['img_name']);
}
	$delete = $conn->prepare("DELETE FROM `news` WHERE id = :id");
	$delete->execute(array('id' => $_GET['id']));

	if($delete){
		$authorSelect = $conn->query("SELECT * FROM `users` WHERE id = '".$_SESSION['USER_ID']."'");
							$author = $authorSelect->fetch();
							if($author['role']=="int_author"){
								header("location:../news.php?delete=success");
							}
							if($author['role']=="tech_editor"){
								header("location:../news_tech_editor.php?delete=success");
							}
							if($author['role']=="lang_editor"){
								header("location:../news_lang_editor.php?delete=success");
							}
							if($author['role']=="chief_editor"){
								header("location:../news_chief_editor.php?delete=success");
							}
								exit();

	}
	else{
		echo $delete->errorInfo();
	}
?>